home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol287 / hview.arc / HVIEW.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-08-24  |  6.2 KB  |  280 lines

  1. ; HercView.asm -- displays a text file on the screen using
  2. ;   the Hercules board's graphics mode.
  3.  
  4. dos    equ    21h        ;the DOS interrupt vector
  5.  
  6. @rddev    equ    3fh        ;read a device
  7. @exit    equ    04ch        ;terminate process
  8.  
  9. select    equ    03b4h        ;select 6845 register
  10.  
  11. mode    equ    03b8h        ;display mode control port
  12. config    equ    03bfh        ;software configuation port
  13.  
  14. cr    equ    0dh
  15.  
  16. ; use the following line if you want to use graphics page 1
  17. ; hires    equ    0b800h        ;segment for graphics page one
  18.  
  19. hires    equ    0b000h        ;segment for graphics page zero
  20.  
  21. buf    equ    [0080h]        ;our buffer
  22.  
  23. entry    proc    near
  24.     mov    ax,hires    ;first put the segment of the graphics
  25.     mov    es,ax        ; screen into ES
  26.  
  27.     call    grafon        ;turn on graphics mode
  28.  
  29. init    call    grafclr        ;and clear the screen
  30.     movw    lmarg,0        ;set left margin to zero for first pass
  31.  
  32. init2    mov    ax,lmarg    ;set xcoord equal to left margin
  33.     mov    xcor,ax
  34.     xor    ax,ax        ;set ycoord equal to top of screen
  35.     mov    ycor,ax
  36.  
  37. next    mov    ah,@rddev    ;read one character from stdin
  38.     xor    bx,bx        ;stdin == device number zero
  39.     mov    cx,1        ;load one character
  40.     mov    dx,offset(buf)    ;into our buffer
  41.     int    dos        ;do it, DOS, please
  42.  
  43.     test    ax,ax        ;are we at EOF?
  44.     jz    done
  45.  
  46. ; at this point, ax = 0001h.
  47.  
  48.     mov    al,buf        ;what character did we get?
  49.  
  50.     cmp    al,cr        ;carriage return?
  51.     jnz    ncr
  52.  
  53. ; for simplicity, the only control character that the program reacts
  54. ; to is CR.  CR performs a CR/LF on the screen.  Thus, nonstandard
  55. ; text files which use LFs withour CRs for multiple blank lines
  56. ; will lose the blank lines.
  57.  
  58.     mov    al,lmarg    ;set xcoord back to left margin
  59.     mov    xcor,al
  60.     addb    ycor,2        ;bump the ycoord by two (will explain later)
  61.  
  62.     cmpb    ycor,86        ;are we at the bottom of the screen?
  63.     jb    next        ;no, continue processing
  64.  
  65.     xorb    lmarg,90    ;yes, toggle left margin from 0 <-> 90(dec)
  66.     jnz    init2        ;if we are on second half, do partial init
  67.  
  68. ; at this point, the entire screen has been filled with stuff
  69.     call    wait        ;wait for a keypress
  70.     jmps    init        ;and start the whole thing over
  71.  
  72. ncr    sub    al,20h        ;is it a control character?
  73.     jb    next        ;yes, ignore it.
  74.  
  75. ; formula is
  76. ;     address == offset(table start) + (asc(char) - 32(dec) ) * 8
  77.  
  78.     shl    ax        ;remember, ah is already zero
  79.     shl    ax
  80.     shl    ax        ;there, multiplied by 8
  81.  
  82.     add    ax,offset(table)
  83.     mov    dot,ax        ;save the address
  84.     call    plot        ;and plot the character
  85.  
  86.     incb    xcor        ;advance cursor
  87.  
  88.     jmps    next        ;and do it again
  89.  
  90. done    call    wait        ;let user see last screen
  91.     call    texton        ;and switch to text mode
  92.     jmp    byebye        ;then return to DOS
  93.  
  94. ; the only data for this section:
  95.  
  96. lmarg    dw    0        ;current left margin
  97.  
  98.     endp    entry
  99.  
  100. ; turn on graphics mode
  101.  
  102. grafon    proc    near
  103.     mov    dx,config    ;prepare to configure card
  104. ; use the following line if you want to use graphics page one
  105. ;    mov    al,3        ;turn on all options
  106.  
  107.     mov    al,1        ;permit graphics but disable page one
  108.     out    dx,al
  109.  
  110.     mov    si,offset(gtbl)    ;config card using table
  111.     call    setmode
  112.  
  113.     mov    dx,mode        ;set graphics page
  114. ; use the following line if you want to use graphics page one
  115. ;    mov    al,0aah        ;use graphics page one
  116.  
  117.     mov    al,02ah        ;use graphics page zero
  118.     out    dx,al
  119.     ret
  120.  
  121. ; table for proper graphics initialization
  122.  
  123. gtbl    db    35h,2dh,2eh,7,5bh,2,57h,57h,2,3,0,0
  124.     endp
  125.  
  126. ; turn off graphics mode
  127.  
  128. texton    proc    near
  129.     mov    si,offset(ttbl)    ;config card using table
  130.     call    setmode
  131.  
  132.     mov    dx,mode        ;set text mode
  133.     mov    al,028h        ;page zero text
  134.     out    dx,al
  135.     ret
  136.  
  137. ; table to deactivate graphics
  138.  
  139. ttbl    db    61h,50h,52h,0fh,19h,6,19h,19h,2,0dh,0bh,0ch
  140.     endp
  141.  
  142. ; takes a table address passed in si and initializes the Herc card
  143. ; accordingly.
  144.  
  145. setmode    proc    near
  146.     cld            ;move forwards through list
  147.  
  148.     mov    dx,mode        ;blank the screen, so we don't zap
  149.     xor    al,al        ; the monitor
  150.     out    dx,al
  151.  
  152.     mov    dx,select
  153.     mov    cx,11        ;table is 11 bytes long
  154.     xor    ah,ah
  155.  
  156. setm1    mov    al,ah        ; port select <- register number
  157.     out    dx,al
  158.     inc    dx
  159.     lodsb            ; port (select+1) <- register value
  160.     out    dx,al
  161.     dec    dx
  162.     inc    ah
  163.     loop    setm1
  164.     ret
  165.     endp
  166.  
  167. ; plot takes the coordinates in xcoord and ycoord and plots a character
  168. ; on the screen.  The address for the character definition is contained
  169. ; in dot.
  170.  
  171. ; The screen coordinates are 0 <= x <= 180 and 0 <= y <= 87.
  172. ;   (Physical screen coordinates are 720 x 348, but to simplify the
  173. ;    calculations, we plot in chunks of 4 x 4 pixels.)
  174. ;    Since characters are 8 dots high, we need to increment ycoord
  175. ;    twice to get to the next line.)
  176.  
  177. plot    proc    near
  178.  
  179. ; formula is
  180. ;    address == (ycoord * 90 (dec)) + (xcoord DIV 2)
  181.  
  182.     mov    al,ycor
  183.     mulb    ninety
  184.  
  185.     mov    bx,xcor
  186.     shr    bx
  187.     add    bx,ax
  188.  
  189. ; dl == screen mask.  (MSB is displayed on the left)
  190. ;  xcoord even:  mask == 0f0h
  191. ;  xcoord odd:   mask == 00fh
  192.  
  193.     mov    dl,0fh
  194.     testb    xcor,1
  195.     jnz    plot1
  196.     not    dl
  197.  
  198. plot1
  199.     mov    si,dot        ;si holds address of character descriptor
  200.     cld            ;move forwards
  201.     mov    cx,4        ;do first four rows
  202.  
  203. ; screen mapping is sort of weird, so we have to plot the character
  204. ; in two parts.
  205.  
  206. plot2    lodsb
  207.     xor    al,es:[bx]    ;put the byte on the screen
  208.     and    al,dl
  209.     xor    es:[bx],al
  210.  
  211.     add    bx,2000h    ;move down a physical row
  212.     loop    plot2
  213.  
  214. ; 32678 == 08000h - 90 (dec)
  215.     sub    bx,32678    ;move down another row
  216.     mov    cx,4        ;do the last four rows
  217.  
  218. plot3    lodsb
  219.     xor    al,es:[bx]    ;put the byte on the screen
  220.     and    al,dl
  221.     xor    es:[bx],al
  222.  
  223.     add    bx,2000h    ;move down another row
  224.     loop    plot3
  225.  
  226. ; all done
  227.     ret
  228.  
  229. ycor    dw    0
  230. xcor    dw    0
  231. dot    dw    0        ;address of picture box (4 x 4 pixels)
  232.  
  233. ninety    db    90        ;constant
  234.  
  235.     endp
  236.  
  237. ; erase the graphics screen by writing zeros to the whole thing
  238.  
  239. grafclr    proc    near
  240.     cld            ;move forwards
  241.     mov    di,0        ;di points into the screen
  242.     xor    ax,ax
  243.     mov    cx,4000h    ;4000h words == 8000h bytes
  244.  
  245.     rep            ;write 8000h zeros
  246.     stosw
  247.  
  248.     ret
  249.  
  250.     endp
  251.  
  252. ; pause for a keypress.  If the user type ctrl-break or ctrl-c,
  253. ; the program exits.
  254.  
  255. wait    proc    near
  256.     xor    ah,ah        ;call BIOS keyboard routine
  257.     int    016h
  258.  
  259.     cmp    al,0        ;ctrl-break typed?
  260.     jz    bye
  261.  
  262.     cmp    al,3        ;ctrl-c typed?
  263.     jz    bye
  264.  
  265.     ret            ;no, return to caller
  266.  
  267. bye    pop    ax        ;clean the stack. (not really necessary)
  268.     endp            ;fall through to byebye routine.
  269.  
  270. byebye    proc    near
  271.     call    texton        ;reactivate text screen
  272.     mov    ah,@exit
  273.     xor    al,al        ;no error code
  274.     int    dos        ;say goodnight, Gracie.
  275.     endp
  276.  
  277. ; after assembling, use DEBUG to append the graphics table here.
  278.  
  279. table    ds    0
  280.